package com.example.demo.service.Impl;

import com.example.demo.domain.Address;
import com.example.demo.repository.AddressMapper;
import com.example.demo.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    AddressMapper addressMapper;

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public void addAddress(Address address) {
        addressMapper.addAddress(
                address.getId(),
                address.getAddress(),
                address.getTimes(),
                address.getUid()
        );
    }




    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public void delAddress(int id) {
        addressMapper.delAddressById(id);
    }

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Address getOnlyAddressById(Integer id) {
        Address address = addressMapper.getOnlyAddressById(id);
        return address;
    }

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public List<Address> getAddressByUid(Integer uid) {
        return addressMapper.getAddressByUid(uid);
    }

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public void addPartAddress(String address, Integer uid,String times) {
         addressMapper.addPartAddress(address,uid,times);
    }

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public void saveAddress(Address address) {
        addressMapper.saveAddress(
                address.getId(),
                address.getAddress(),
                address.getTimes(),
                address.getUid()
        );
    }
}
